<?php

namespace App\Admin\Controllers;

use DB;
use Validator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use App\PacketLog;


class RedPacketController extends Controller
{
	/**
	 * [index 红包列表]
	 * @return [type] [description]
	 */
	public function index(Request $request)
	{
		$packets = PacketLog::where('id', '>', 0);
		if ($request->input('time')) {
			$period = $request->input('time');
			$time_arr = explode('~', $request->input('time'));
			$begin = $time_arr[0];
			$end = $time_arr[1];
			$packets = $packets->whereBetween('created_at', [$begin, $end]);
		}
		$packets = $packets->orderBy('created_at', 'DESC')->paginate(15);
		$packets->appends([
				'time' => $request->input('time')
			]);
		return view('admin.redpacket.index', compact('packets'));
	}

	/**
	 * [remove 删除记录]
	 * @param  PacketLog $packet [description]
	 * @return [type]            [description]
	 */
	public function remove(PacketLog $packet)
	{
		$packet->delete();
		return back();
	}

	/**
	 * [detail 红包详情]
	 * @return [type] [description]
	 */
	public function detail(PacketLog $packet)
	{
		return view('admin.redpacket.detail', compact('packet'));
	}




}	